﻿// IntToStringConverter
//
// WPF data binding conversion class for converting int to String
// 
// FLMScan - Featured by FabLab Munich

using System;
using System.Text;
using System.Windows.Data;

namespace FLMScan.WPF
{
    [ValueConversion(typeof(object), typeof(string))]    
    public class IntToStringConverter : BaseConverter, IValueConverter    
    {
        // convert from int to string
        public object Convert(object value, Type targetType, object parameter,
                          System.Globalization.CultureInfo culture)
        {
            int integer = 0;

            try
            {
                integer = (int)value;
            }
            catch (System.Exception)
            {
                System.Diagnostics.Debug.Assert(false);
            }

            return integer.ToString();            
        }

        // convert from string to int
        public object ConvertBack(object value, Type targetType, object parameter,
                        System.Globalization.CultureInfo culture)
        {            
            return int.Parse((string)value); 
        }            
    }
}
